package com.itheima.work1128;

public class window extends Thread{

    public window(String name) {
        super(name);
    }
    public window() {
    }
    //用继承Thread类的方式重新实现卖票案例,通过同步代码块解决安全问题
    @Override
    public  void run(){
        while (ticket.n>=2){
            synchronized (ticket.class){
                System.out.println(Thread.currentThread().getName()+"窗口卖了一张票\t  现在还剩"+ticket.n+ "张票");
                ticket.n--;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}
